package com.ruoyi.web.controller.subscribe;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.subscribe.Subscribe;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.system.service.ISubscribeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预约服务管理Controller
 * 
 * @author ruoyi
 * @date 2023-04-08
 */
@RestController
@RequestMapping("/system/subscribe")
public class SubscribeController extends BaseController
{
    @Autowired
    private ISubscribeService subscribeService;

    /**
     * 查询预约服务管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:subscribe:list')")
    @GetMapping("/list")
    public TableDataInfo list(Subscribe subscribe)
    {
        startPage();
        List<Subscribe> list = subscribeService.selectSubscribeList(subscribe);
        return getDataTable(list);
    }

    /**
     * 导出预约服务管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:subscribe:export')")
    @Log(title = "预约服务管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Subscribe subscribe)
    {
        List<Subscribe> list = subscribeService.selectSubscribeList(subscribe);
        ExcelUtil<Subscribe> util = new ExcelUtil<Subscribe>(Subscribe.class);
        util.exportExcel(response, list, "预约服务管理数据");
    }

    /**
     * 获取预约服务管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:subscribe:query')")
    @GetMapping(value = "/{subscribeId}")
    public AjaxResult getInfo(@PathVariable("subscribeId") Integer subscribeId)
    {
        return success(subscribeService.selectSubscribeBySubscribeId(subscribeId));
    }

    /**
     * 新增预约服务管理
     */
    @PreAuthorize("@ss.hasPermi('system:subscribe:add')")
    @Log(title = "预约服务管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Subscribe subscribe)
    {
        return toAjax(subscribeService.insertSubscribe(subscribe));
    }

    /**
     * 修改预约服务管理
     */
    @PreAuthorize("@ss.hasPermi('system:subscribe:edit')")
    @Log(title = "预约服务管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Subscribe subscribe)
    {
        return toAjax(subscribeService.updateSubscribe(subscribe));
    }

    /**
     * 删除预约服务管理
     */
    @PreAuthorize("@ss.hasPermi('system:subscribe:remove')")
    @Log(title = "预约服务管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{subscribeIds}")
    public AjaxResult remove(@PathVariable Integer[] subscribeIds)
    {
        if (subscribeService.deleteSubscribeBySubscribeIds(subscribeIds)==1){
            return success();
        }
        return error("您选中了未处理的预约请求 请处理在删除o~~~~");
    }
}
